﻿using System;
using MPBlog.Core;
using MPBlog.DAL;

namespace MPBlog.UserControls
{
    public class NewArticleBase : UCBase
    {
        #region - 控件声明 -

        protected System.Web.UI.WebControls.TextBox txtArticleTitle;
        protected FredCK.FCKeditorV2.FCKeditor txtArticleContent;
        protected System.Web.UI.WebControls.Button btnSubmit;


        #endregion


        protected override void OnLoad(EventArgs e)
        {
            base.OnLoad(e);

            btnSubmit.OnClientClick = string.Format("if(!MPBlog.validate.addArticle('{0}','{1}')){{return false;}}", txtArticleTitle.ClientID, txtArticleContent.ClientID);
        }

        protected void btnSubmitClicked(object sender, EventArgs e)
        {
            string title = txtArticleTitle.Text;
            string content = txtArticleContent.Value;

            if (string.IsNullOrEmpty(title) || string.IsNullOrEmpty(content))
            {
                Page.Message("标题或者内容不能为空", Utils.MessageType.error, 3000);
                return;
            }

            ArticleDao articleDao = new ArticleDao();
            articleDao.Create(new Model.Article()
                                  {
                                      Title = title,
                                      Content = content,
                                      PublishTime = DateTime.Now,
                                      Tags = "1,2",
                                      CategoryId = 2,
                                      Author = "scott"
                                  });
        }
    }
}